#ifndef __WX_CLIENT__ASYNC_H__
#define __WX_CLIENT__ASYNC_H__

#include "poller.h"
#include "timerlist.h"
#include "list.h"
#include "poll_thread.h"
#include "log.h"
#include "binpacket.h"
#include <map>
#include <sstream>

#define HTTP_HEADER		map<string, string>

class CClientAsync : public CPollerObject , public CTimerObject
{
	enum STAT {INIT=0,RECVING,RECVDONE,SENDING,SENDDONE,DONE};
public:
	CClientAsync(CPollThread *o, int fd);
	virtual ~CClientAsync ();
	
	int Attach();
	
	virtual void InputNotify (void);
	virtual void OutputNotify (void);
	virtual void TimerNotify(void);
	int ProcessHeader(void);
private:
	void ErrorProcess(const char* errMsg);

	
	void InitProcess(int32_t len);	
	int32_t Recv();
	
	void RecvingProcess(int32_t len);	
	void RecvDoneProcess();	
	void SendingProcess();	
	void DoneProcess();	
	void RecvCheck();
private:	
	CPollThread *owner;
	STAT stat;
	char *recvbuf;
	HTTP_HEADER m_headers;
	string m_body;
	int32_t m_content_len;

	char *m_pbeg;
	char *m_pend;
	uint32_t m_bufferlen;
	int32_t offset;

	time_t m_lasttime;
	stringstream outbuf;

};

#endif

